perm filename CH4OLD[206,JMC] blob
sn#237429 filedate 1976-09-17 generic text, type C, neo UTF8
COMMENT ⊗ VALID 00002 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 This is the first part of chapter 4 from the old version of the manual.
C00008 ENDMK
C⊗;
This is the first part of chapter 4 from the old version of the manual.
.sec LISP SELF-APPLIED
.ss The list representation of LISP functions.
When one computes with symbolic expressions, it is necessary to face
the fact that the most convenient notation for reading and writing is not
the most convenient notation for symbolic data from the point of view of the
programmer who must write programs for manipulating the data. So far, we have
resolved this dilemma by using S-expressions for data and writing LISP functions
and programs in a language that is hopefully convenient for reading and writing.
Now LISP programs are also symbolic information, and we want to be able to
manipulate LISP programs with LISP functions and programs. In order to do this
we use a representation of LISP functions by LISP lists. In Chapter 6, we shall
discuss procedures for translating between S-expression notation and other
notations for symbolic information.
We use the following conventions:
1. Variables are represented by atomic symbols composed of upper case
letters. Thus the variable %3x%* will normally be represented by the
corresponding upper case letter %5X%1.
2. An S-expression %3e%* will be represented as %5(QUOTE %3e%*)%1. Thus
the atom %5X%1 is represented by %5(QUOTE X)%1.
3. The basic LISP functions %3car, cdr, cons, atom%1 and %3eq%1,
the functions %3list%1 and %3null%1 derived from them are represented by
writing the words in upper case. Thus we have %5CAR, CDR, CONS, ATOM, EQ, LIST,
%1and %5NULL. Defined functions are also represented by atoms, e.g. %5ALT, DIFF,%1 etc.
4. Numbers are represented by the S-expression notation for numbers
without %5QUOTE%1, and the special atoms %5T%1 and %5NIL%1 are represented by themselves
without QUOTE. Avoiding QUOTE here is for convenience and can be regarded as
using variables T and NIL whose permanent values are the S-expressions T and
NIL.
5. The application of a function to arguments is represented by a list
the first element of which is the function name and the remaining elements are
the arguments in the same order. Thus %3f%2[%3x%2, %3y%2]%1 is represented by
(F X Y).
.NOFILL
6. The conditional expression
%4if%3 p%61%4 then %3e%61%3 ... %4else if %3p%6n%4 then %3e%6n%1
is represented by
(COND (%3p%61%3 e%61%2) ... (%3p%6n%3 e%6n%2)).
There is no way of representing a final %4else%1, so
%4if%3 p %4then%3 a %4else %3b%1
is represented by
(COND (%3p a%2)(%5T %3b%2)).
Thus
%4if n %3u %2∨ %4n d %3u %4then%3 u %4else a %3u . %3alt %4dd %3u%1
is represented by
(COND ((OR (NULL U) (NULL (CDR U))) U) (T (CONS (CAR U) (ALT (CDDR U))))).
.FILL
7. The λ-expression λ%3x...z%2: %1 is represented by
(LAMBDA (X ... Z) %3e%2). Thus
.NOFILL
λ%3x y%2: %4if n %3x %4 then %3y %4else a %3x . append%2[%4d %3x%2,%3 y%2]%1
is represented by
(LAMBDA (X Y) (COND ((NULL X) Y) (T (CONS (CAR X) (APPEND (CDR X) Y)))))).
.FILL
8. Finally, %4label%2[%3fname%2, %3e%2]%1 is represented by (LABEL %3fname e%1),
so that
%4label%2[%3alt%2, λ%3x%2: %4if n %3x %2∨ %4n d %3x %4then %3x
%4else a %3x . alt%2[%4dd%3 x%2]]%1
.NOFILL
is represented by
(LABEL ALT (LAMBDA (X) (COND ((OR (NULL X) (NULL (CDR X))) X)
(T (CONS (CAR X) (ALT (CDDR X))))))).
.FILL
Actually, %4label%1 is rarely used in LISP programming,
because it names a function for immediate use only, and usually one
wants to attach a function definition to its name for later use in
several places in the program. The notation for making definitions varies
with the implementation of LISP.